import java.util.LinkedList;
import java.util.Queue;

public class LC_225 {
}
class MyStack {
    Queue<Integer> que1;
    Queue<Integer> que2;
    int size;
    public MyStack() {
        que1 = new LinkedList<>();
        que2 = new LinkedList<>();
        size = 0;
    }

    public void push(int x) {
        que1.offer(x);
        size++;
    }

    public int pop() {
        if(size == 0)return 0;
        size--;
        int key = 0;
        while(que1.size() != 1){
            que2.offer(que1.poll());
        }
        key = que1.poll();
        while(que2.size() != 0){
            que1.offer(que2.poll());
        }
        return key;
    }

    public int top() {
        if(size == 0)return 0;

        int key = 0;
        while(que1.size() != 0){
            if(que1.size() == 1){
                key = que1.peek();
            }
            que2.offer(que1.poll());

        }
        while(que2.size() != 0){
            que1.offer(que2.poll());
        }
        return key;
    }

    public boolean empty() {
        return size == 0 ? true : false;
    }
}